/**
 * <b>项目名：</b>ht-web<br/>  
 * <b>包名：</b>com.flea.hclv.controller<br/>  
 * <b>文件名：</b>PersonInfoController.java<br/>  
 * <b>版本信息：</b>1.0<br/>  
 * <b>日期：</b>2019年8月8日 上午11:25:34<br/>  
 * <b>COPYRIGHT 2010-2012 ALL RIGHTS RESERVED 虫子科技</b>-版权所有<br/>
 */
package com.flea.hclv.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.flea.hclv.model.entity.HVisitor;
import com.flea.hclv.model.entity.PersonInfo;
import com.flea.hclv.service.PersonInfoService;
import com.flea.hclv.util.ServerResponse;
import com.flea.system.base.util.StringUtil;
import com.flea.system.bean.FleaPage;
import com.flea.system.entity.OrgDept;
import com.flea.system.entity.OrgUser;
import com.flea.system.platform.session.FleaOrgUtils;

/**
 * @description TODO
 * @createTime 2019年8月8日 上午11:25:34
 * @modifyTime 
 * @author myflea@163.com
 * @version 1.0
 */
@Controller
@RequestMapping("/flea/hclv/person/")
public class PersonInfoController {
	@Autowired
	private PersonInfoService personInfoService;
    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public ServerResponse<String> saveOrUpdate(HttpServletRequest request, HttpServletResponse response) throws Exception {
        String userId = FleaOrgUtils.getCurUserUuid(request);
        OrgDept currentUserDept = FleaOrgUtils.getCurrentUserDept(request);
        String model = request.getParameter("model");

        PersonInfo personInfo = JSON.parseObject(model,PersonInfo.class);
        ServerResponse<String> serverResponse = personInfoService.saveOrUpdate(userId,currentUserDept,personInfo);
        return serverResponse;
    }
    /**
     * 查找所有  （供管理员使用）
     * @param request request
     * @param paging 分页对象
     * @param zhName 中文名字
     * @param enName 英文名
     * @return list
     */
    @RequestMapping("selectAll")
    @ResponseBody
    public ServerResponse<FleaPage<PersonInfo>> selectAll(HttpServletRequest request, FleaPage<HVisitor> paging,
                                                        @RequestParam(value = "projectCode",defaultValue = "")String projectCode,
                                                        @RequestParam(value = "name",defaultValue = "")String name,
                                                        @RequestParam(value = "personNo",defaultValue = "")String personNo,
                                                        @RequestParam(value = "team",defaultValue = "")String team
                                                        ){
        OrgDept currentUserDept = FleaOrgUtils.getCurrentUserDept(request);
        OrgUser orgUser = FleaOrgUtils.getCurUser(request);
        String bdType = orgUser.getExtend1();
        
        if(StringUtil.isEmpty(bdType)) {
        	return ServerResponse.createByErrorMessage("当前用户没有权限查看人员信息功能，请联系管理员");
        }else if(bdType.equals("BD000")) {
        	 return personInfoService.selectAll(paging.getCurPage(),paging.getPageSize(),projectCode,name,personNo,team);
        }else {
        	 return personInfoService.selectAll(bdType,paging.getCurPage(),paging.getPageSize(),projectCode,name,personNo,team);
        }
        
        
       

    }
    @RequestMapping("deleteByIds")
    @ResponseBody
    public ServerResponse<String> deleteByIds(HttpServletRequest request,HttpServletResponse response, @RequestParam("ids")String ids){
        String userId = FleaOrgUtils.getCurUserUuid(request);
        List<String> idList = JSON.parseArray(ids,String.class);
        ServerResponse<String> serverResponse =  personInfoService.deleteByIds(userId,idList);
        return serverResponse;
    }
    @RequestMapping("findPicById")
    @ResponseBody
    public ServerResponse findPicById(HttpServletRequest request,HttpServletResponse response, @RequestParam("id")String id){
    	String userId = FleaOrgUtils.getCurUserUuid(request);
    	if(StringUtil.isEmpty(id)) {
    		ServerResponse.createBySuccessMessage("传递的参数Id为空");
    	}
    	ServerResponse serverResponse =  personInfoService.findPicById(id);
    	return serverResponse;
    }
    @RequestMapping("init")
    @ResponseBody
    public ServerResponse<String> init(HttpServletRequest request,HttpServletResponse response, @RequestParam("ids")String ids){
    
    	ServerResponse<String> serverResponse =  personInfoService.init();
    	return serverResponse;
    }
    @RequestMapping("initCode")
    @ResponseBody
    public ServerResponse<String> initCode(HttpServletRequest request,HttpServletResponse response){
    	
    	ServerResponse<String> serverResponse =  personInfoService.initCode();
    	return serverResponse;
    }
    @RequestMapping("statisticsByProject")
    @ResponseBody
    public ServerResponse<JSONObject> statisticsByProject(HttpServletRequest request,HttpServletResponse response){
    	
    	ServerResponse<JSONObject> serverResponse =  personInfoService.findGroupByProject();
    	return serverResponse;
    }
    @RequestMapping("statisticsByGz")
    @ResponseBody
    public ServerResponse<String> statisticsByGz(HttpServletRequest request,HttpServletResponse response){
    	
    	ServerResponse<String> serverResponse =  personInfoService.initCode();
    	return serverResponse;
    }
    @RequestMapping("statisticsByTeam")
    @ResponseBody
    public ServerResponse<String> statisticsByTeam(HttpServletRequest request,HttpServletResponse response){
    	
    	ServerResponse<String> serverResponse =  personInfoService.initCode();
    	return serverResponse;
    }



}
